home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98c.txt / 000151_icon-group-sender _Mon Dec 21 09:39:52 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  1KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA04197
  4.     for icon-group-addresses; Mon, 21 Dec 1998 09:39:46 -0700 (MST)
  5. Message-Id: <199812211639.JAA04197@baskerville.CS.Arizona.EDU>
  6. To: icon-group@optima.CS.Arizona.EDU
  7. Date: Sun, 20 Dec 1998 01:02:51 GMT
  8. From: static@operamail.com.au (Wade Bowmer)
  9. Subject: Re: Small Icon programming problem
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13. On 17 Dec 1998 13:21:34 -0500, Ralph Griswold <ralph@baskerville.CS.Arizona.EDU> wrote:
  14. > Here's a small Icon programming problem for you to tackle:
  15. >     Write a procedure digsort(i) that returns the integer that
  16. >     results from sorting the digits of i, preserving sign.  For
  17. >     example, digsort(201) should return 12 and digsort(-1042)
  18. >     should return -124.  You may assume i is an integer.
  19. > You could aim for brevity, speed, and/or clarity.
  20.  
  21. I dunno what to aim for. However, trying it out raises a question: what is digsort(737) supposed to produce? 377 or 37? 
  22.  
  23. My solution outputs the former.
  24.  
  25. procedure digsort(in)
  26.  
  27.     s := string(in) | return fail
  28.     t := table(0)
  29.     every t[!s] +:= 1
  30.     s := ""
  31.     every i := !sort(t,1) do
  32.           s ||:= repl(i[1], i[2])
  33.     return integer(s)
  34.  
  35. end 
  36.  
  37. Wade.
  38.  
  39.  
  40.